package com.example.activity_05;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

/**
 * 进度条
 */
public class MainActivity extends Activity {
    private ProgressBar firstprogressbar;
    private ProgressBar secondprogressbar;
    private Button myButton;
    private int i=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        firstprogressbar=findViewById(R.id.firstprogressbar);
        secondprogressbar=findViewById(R.id.secondprogressbar);
        myButton=findViewById(R.id.myButton);
        myButton.setOnClickListener(new myButtonListener());
    }
    class myButtonListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            if(i==0){
                firstprogressbar.setVisibility(View.VISIBLE);
                secondprogressbar.setVisibility(View.VISIBLE);
            }
            else if(i<firstprogressbar.getMax()){
                firstprogressbar.setProgress(i);
                firstprogressbar.setSecondaryProgress(i+10);
            }
            else {
                firstprogressbar.setProgress(View.GONE);
                secondprogressbar.setSecondaryProgress(View.GONE);
            }
            i=i+20;
        }
    }
}
